<template>
  <div ref="chart" style="width: 100%; height: 300px"></div>
</template>

<script>
// 引入ECharts主模块
import * as echarts from "echarts";
import {getsendStatistics,getnumberStatistics } from "@/api/combat/userzh";

export default {
  name: "pieChart",
  data() {
    return {
      userId: "",
    };
  },
  mounted() {
    let userId = this.$route.query.userId;
    this.getStatisticsDataFn(userId);
  },
  methods: {
    getStatisticsDataFn(userId) {
      getnumberStatistics(userId).then((res) => {
        if (res.code == 200) {
          this.initFn(res.data);
        }
      });
    },
    initFn(resData) {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(this.$refs.chart);

      //饼图
      let option = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          top: "5%",
          left: "center",
        },
        series: [
          {
            name: "统计",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              {
                value: resData.userFocusNum,
                name: "关注",
              },
              {
                value: resData.userBlogNum,
                name: "博客",
              },
              {
                value: resData.userFansNum,
                name: "粉丝",
              },
            ],
          },
        ],
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
  },
};
</script>

<style scoped>
/* 你可以在这里添加一些CSS样式 */
</style>
